package com.example.springcloud.service.impl;

import java.util.Date;
import java.util.List;

import com.example.springcloud.mapper.UsersMapper;
import com.example.springcloud.request.PostCommentsRequest;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.springcloud.mapper.CommentsMapper;
import com.example.springcloud.domain.Comments;
import com.example.springcloud.service.ICommentsService;

/**
 * 种草文章评论Service业务层处理
 * 
 * @author hx
 * @date 2025-02-18
 */
@Service
public class CommentsServiceImpl implements ICommentsService 
{
    @Autowired
    private CommentsMapper commentsMapper;
    @Autowired
    private UsersMapper usersMapper;

    /**
     * 查询种草文章评论
     * 
     * @param id 种草文章评论主键
     * @return 种草文章评论
     */
    @Override
    public Comments selectCommentsById(Long id)
    {
        return commentsMapper.selectCommentsById(id);
    }

    /**
     * 查询种草文章评论列表
     * 
     * @param comments 种草文章评论
     * @return 种草文章评论
     */
    @Override
    public List<Comments> selectCommentsList(Comments comments)
    {
        return commentsMapper.selectCommentsList(comments);
    }

    /**
     * 新增种草文章评论
     * 
     * @param comments 种草文章评论
     * @return 结果
     */
    @Override
    public int insertComments(Comments comments)
    {
        return commentsMapper.insertComments(comments);
    }

    /**
     * 修改种草文章评论
     * 
     * @param comments 种草文章评论
     * @return 结果
     */
    @Override
    public int updateComments(Comments comments)
    {
        return commentsMapper.updateComments(comments);
    }

    /**
     * 批量删除种草文章评论
     * 
     * @param ids 需要删除的种草文章评论主键
     * @return 结果
     */
    @Override
    public int deleteCommentsByIds(Long[] ids)
    {
        return commentsMapper.deleteCommentsByIds(ids);
    }

    /**
     * 删除种草文章评论信息
     * 
     * @param id 种草文章评论主键
     * @return 结果
     */
    @Override
    public int deleteCommentsById(Long id)
    {
        return commentsMapper.deleteCommentsById(id);
    }

    /**
     * 发布评论
     *
     * @param postCommentsRequest 评论请求参数
     * @return 结果
     */
    @Override
    public AjaxResult postComments(PostCommentsRequest postCommentsRequest) {
        Comments comments = new Comments();
        comments.setPostId(postCommentsRequest.getPostId());
        comments.setUserId(postCommentsRequest.getUserId());
        comments.setContent(postCommentsRequest.getContent());
        comments.setCreatedAt(new Date());
        commentsMapper.insertComments(comments);
        return AjaxResult.success("发布评论成功");
    }
}
